package com.life.notes.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.life.notes.common.entity.BaseEntity;
import com.life.notes.common.validator.Create;
import com.life.notes.common.validator.FieldRepeatValidator;
import com.life.notes.common.validator.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * 手机号实体
 * @Author Sans
 * @CreateTime 2019/9/14 15:57
 */
@Data
@ApiModel(description = "笔记管理-手机号基础信息表")
@TableName("t_phone")
// 对注解分组的排序，可以通脱他判断先后顺序
//@GroupSequence({FieldRepeatValidator.class,NotNull.class, Default.class})
@FieldRepeatValidator(field = "name", message = "名称重复，请重新输入名称！")
public class PhoneEntity extends BaseEntity {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键ID  groups:标识在更新的时候才能验证非空
	 */
	@ApiModelProperty(value = "主键ID")
	@TableId(value="id", type= IdType.AUTO)
	@NotNull(message = "id不能为空", groups={Update.class})
	private Integer id;
	/**
	 * 名称
	 */
	@ApiModelProperty(value = "名称")
	@TableField("name")
	@NotBlank(message = "名称不能为空", groups = {Create.class, Update.class})
	@Length(max = 100, message = "名称不能超过100个字符")
	@Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9\\*]*$", message = "名称限制：最多100字符，包含文字、字母和数字")
	private String name;

	/**
	 * 性别 0:男 1:女
	 */
	@ApiModelProperty(value = "性别 0:男 1:女")
	@TableField("sex")
	private String sex;
	/**
	 * 手机号码
	 */
	@ApiModelProperty(value = "手机号码")
	@TableField("phone")
	@NotBlank(message = "手机号不能为空")
	@Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")
	private String phone;
	/**
	 * 副手机号码
	 */
	@ApiModelProperty(value = "副手机号码")
	@TableField("vice_phone")
	private String vicePhone;
	/**
	 * 座机号码
	 */
	@ApiModelProperty(value = "座机号码")
	@TableField("landline")
	private String landline;
	/**
	 * 所有者ID
	 */
	@ApiModelProperty(value = "所有者ID")
	@TableField("user_id")
	private Integer userId;

	@TableField("id_card")
	private String IDCard;

	@Override
	protected Serializable pkVal() {
		return this.id;
	}
}